
package com.csun.cmny.provider.service.impl;

import com.csun.cmny.base.dto.CacReturnDto;
import com.csun.cmny.base.enums.ErrorCodeEnum;
import com.csun.cmny.base.exception.BusinessException;
import com.csun.cmny.provider.exceptions.CacBizException;
import com.csun.cmny.provider.model.vo.CareTypeCountVo;
import com.csun.cmny.provider.service.CacOldmanFeignApi;
import com.csun.cmny.provider.service.CacRpcService;
import com.csun.cmny.util.wrapper.Wrapper;
import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
@Slf4j
@Service
public class CacRpcServiceImpl implements CacRpcService {
    @Resource
    private CacOldmanFeignApi cacOldmanFeignApi;

   @Override
    public List<Map<String, Object>> showAll(Integer oldmanId) {
        Wrapper<List<Map<String, Object>>> wrapper =  cacOldmanFeignApi.getEstimateByOld(oldmanId);
        return wrapper.getResult();
    }

    @Override
    public Integer deleteByOldmanId(Integer oldmanId) {
        return cacOldmanFeignApi.deleteCacOldman(oldmanId);
    }

    @Override
    public List<CacReturnDto> selectCacOldMnr(Integer oldmanId) {
        Wrapper<List<CacReturnDto>> wrapper = cacOldmanFeignApi.selectCacOldMnr(oldmanId);
        if (wrapper ==null){
            throw new BusinessException(ErrorCodeEnum.GL99990002);
        }
        if (wrapper.error()){
            throw new BusinessException(ErrorCodeEnum.GL99990500);
        }
        return wrapper.getResult();
    }

    @Override
    public List<CareTypeCountVo> queryOldmanNumGroupByCareType(List<Integer> oldmanIdList) {
        try {
            Wrapper<List<CareTypeCountVo>> wrapper = cacOldmanFeignApi.queryOldmanNumGroupByCareType(oldmanIdList);
            if (wrapper == null) {
                throw new CacBizException(ErrorCodeEnum.GL99990002);
            }
            if (wrapper.error()) {
                throw new CacBizException(ErrorCodeEnum.GL9999404);
            }
            return wrapper.getResult();
        } catch (Exception e) {
            log.error("queryOldmanNumGroupByCareType = {}", e.getMessage(), e);
        }
        return null;
    }

    @Override
    public List<Integer> queryNeedDailyEvaluateOldmanIdList(Long groupId) {
        try {
            Wrapper<List<Integer>> wrapper = cacOldmanFeignApi.queryNeedDailyEvaluateOldmanIdList(groupId);
            if (wrapper == null) {
                throw new CacBizException(ErrorCodeEnum.GL99990002);
            }
            if (wrapper.error()) {
                throw new CacBizException(ErrorCodeEnum.GL9999404);
            }
            return wrapper.getResult();
        } catch (Exception e) {
            log.error("queryNeedDailyEvaluateOldmanIdList = {}", e.getMessage(), e);
        }
        return null;
    }

    @Override
    public List<Map<String, Object>> selectCacOldManAll() {
        try {
            Wrapper<List<Map<String, Object>>> wrapper = cacOldmanFeignApi.selectCacOldManAll();
            if (wrapper == null) {
                throw new CacBizException(ErrorCodeEnum.GL99990002);
            }
            if (wrapper.error()) {
                throw new CacBizException(ErrorCodeEnum.GL9999404);
            }
            return wrapper.getResult();
        } catch (Exception e) {
            log.error("queryNeedDailyEvaluateOldmanIdList = {}", e.getMessage(), e);
        }
        return null;
    }

    @Override
    public Integer updateLevelCare(List<Map<String, Object>> updateDtos) {
        try {

            Wrapper<Integer> wrapper = cacOldmanFeignApi.updateLevelCare(updateDtos);
            if (wrapper == null) {
                throw new CacBizException(ErrorCodeEnum.GL99990002);
            }
            if (wrapper.error()) {
                throw new CacBizException(ErrorCodeEnum.GL9999404);
            }
            return wrapper.getResult();
        } catch (Exception e) {
            log.error("queryNeedDailyEvaluateOldmanIdList = {}", e.getMessage(), e);
        }
        return null;
    }

    @Override
    public Integer test(List<Map<String, Object>> updateDtos) {
        try {
            Wrapper<Integer> wrapper = cacOldmanFeignApi.test(updateDtos);
            if (wrapper == null) {
                throw new CacBizException(ErrorCodeEnum.GL99990002);
            }
            if (wrapper.error()) {
                throw new CacBizException(ErrorCodeEnum.GL9999404);
            }
            return wrapper.getResult();
        } catch (Exception e) {
            log.error("queryNeedDailyEvaluateOldmanIdList = {}", e.getMessage(), e);
        }
        return null;
    }
}

